/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package udpUnitAdapt;

import java.io.IOException;
import java.net.DatagramSocket;

/**
 *
 * @author axelsben
 */
public class unitServer {
    udpServer us = new udpServer();
    int useSocket = 0;

    unitServer(String server, int port)
    {
        us.setAddress(server);
        us.setSocket(port);
        us.setLogging(false);
        useSocket = port;
        
        srvThread st;
		try {
			st = new srvThread();
	        st.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

    }
    public class srvThread extends Thread
    {
        protected DatagramSocket socket = null;

        public srvThread() throws IOException
        {
            this("unitSrvThread");
        }

        public srvThread(String name) throws IOException
        {
            super(name);
            socket = new DatagramSocket(useSocket);
        }


        @Override
        public void run() {
	        while(true){
	            byte[] byteArray = us.receive(socket);
	            adaptor.unit2app(byteArray);
	        }
        }
    }

}
